/*
 * @Description  : 
 * @Date         : 2021-08-18 11:10:50
 * @Author       : 保锋
 * @LastEditTime : 2021-08-20 14:20:30
 * @LastEditors  : 保锋
 * @FilePath     : \flutter_demo\lib\main.dart
 */
import 'dart:io';

import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'routes/myroute.dart';
import 'routes/routes.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  if (Platform.isAndroid) {
    SystemChrome.setSystemUIOverlayStyle(
        SystemUiOverlayStyle(statusBarColor: Colors.transparent));
  }
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  final botToastBuilder = BotToastInit();
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(750, 1334),
      builder: () => GetMaterialApp(
        ///关闭右上角测试条
        debugShowCheckedModeBanner: false,

        title: '测试',

        ///绑定路由表
        getPages: routes,

        ///设置全局主题
        theme: ThemeData(
          ///浅色模式
          brightness: Brightness.dark,

          ///根颜色
          primarySwatch: Colors.blue,
          primaryColor: Colors.white,
        ),

        ///国际化设置（解决长按TextFiled出现英文（复制、粘贴）的问题）
        localizationsDelegates: const <LocalizationsDelegate<dynamic>>[
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
        ],
        supportedLocales: const <Locale>[
          Locale('zh', 'CN'),
          Locale('en', 'US'),
        ],

        ///全局配置空白处点击取消输入框焦点
        builder: (BuildContext context, Widget? child) {
          return botToastBuilder(
              context,
              GestureDetector(
                onTap: () {
                  final FocusScopeNode currentFocus = FocusScope.of(context);
                  if (!currentFocus.hasPrimaryFocus &&
                      currentFocus.focusedChild != null) {
                    FocusManager.instance.primaryFocus!.unfocus();
                  }
                  // SystemChannels.textInput.invokeMethod('TextInput.hide');
                },
                child: child,
              ));
        },
        navigatorObservers: [MyRouteObserver(), BotToastNavigatorObserver()],

        ///设置初始化路由页面
        initialRoute: '/home',
      ),
    );
  }
}
